<template>
	<view>
		<!-- 我的成绩 -->
		<u-navbar title="我的成绩" title-color="#fff" :background="background" back-icon-color="#ffffff"
			:back-text-style="{color: '#fff'}">
			<view class="slot-wrap">
				<!-- <u-icon name="list-dot" color="#ffffff" size="36" @click="changeModel"></u-icon> -->
			</view>
		</u-navbar>
		<u-search class="searchBar" placeholder="搜索考试" v-model="value" :clearabled="true" @search="searchFunc"
			@custom="searchFunc" :show-action="true"></u-search>
			
		<exam-grade v-for="(item, index) in myResultList.records" :key="item.id" :examGradItem="item" @checkGrade="toGradePage">
		</exam-grade>
		<u-loadmore :status="status" />
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				myResultList: [],
				examList: [],
				value: "",
				status: "loadmore",
				page: 1,
				background: {
					'background-image': 'linear-gradient(45deg, #007fd1, #013cd2)'
				},
			};
		},
		methods: {
			toGradePage(recordId) {
				this.$u.route({
					url: "/pages/exam/examReviewPage",
					params: {
						recordId: recordId,
					},
				});
			},
			searchFunc(value) {
				console.log(value);
				var that = this;
				this.$api.getGradeList(1, value).then((res) => {
					uni.showToast({
						title: "搜索成功",
					});
					console.log(res);
					// console.log('考试列表:',res.values.records);
					that.gradeList = res.values.records;
				});
			},
		},
		onLoad(option) {
			import("@/common/exam_myResults.js").then(myResultList => {
				this.myResultList = myResultList.myResultList
			})
			// this.value = option.examName;
			// if (option.examName) {
			// 	this.$api.getGradeList(1, option.examName)
			// 		.then((res) => {
			// 			console.log(res);
			// 			// console.log('考试列表:',res.values.records);
			// 			this.gradeList = res.values.records;
			// 		});
			// } else {
			// 	this.$api.getGradeList(1, "").then((res) => {
			// 		console.log(res);
			// 		// console.log('考试列表:',res.values.records);
			// 		this.gradeList = res.values.records;
			// 	});
			// }
		},
		onReachBottom() {
			if (this.value == undefined) {
				this.value = ''
			}
			if (this.status === "loadmore") {
				this.page += 1;
				this.status = "loading";
				this.$api.getGradeList(this.page, this.value)
					.then((res) => {
						console.log('res更多', res);
						if (res.values.records.length === 0) {
							this.status = "nomore";
						} else {
							this.gradeList = this.gradeList.concat(res.values.records);
							this.status = "loadmore";
						}
					});
			}
		},
	};
</script>

<style lang="scss">
	.tips {
		color: #eeeeee;
	}

	.searchBar {
		padding: 20upx;
	}
</style>
